package com.gxa.logistics.service.impl;

import com.gxa.logistics.domain.dto.MaterialDTO;
import com.gxa.logistics.domain.dto.TransferrecordDTO;
import com.gxa.logistics.mapper.MaterialMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MaterialServiceImpl {

    @Resource
    private MaterialMapper materialMapper;


    public Map<String, Object> insert(MaterialDTO materialDTO) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增成功");
        materialMapper.insert(materialDTO);
        return map;
    }

    public int delete(Integer material_id) {
        return materialMapper.delete(material_id);
    }
    public Map<String, Object> update(MaterialDTO materialDTO) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "更新成功");
        materialMapper.update(materialDTO);
        return map;
    }

    public List<MaterialDTO> selectMaterialByName(String material_name) {

        return materialMapper.selectMaterialByName(material_name);
    }

    public Map<String, Object> selectMaterialByWarehouseName(String warehouse_name) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "查询成功");
        List<MaterialDTO> materialDTO = materialMapper.selectMaterialByWarehouseName(warehouse_name);
        map.put("data", materialDTO);
        return map;
    }

    public Map<String, Object> selectMaterial(int page, int limit) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", materialMapper.selectMaterialCount());    // 动态统计条数

        int index = (page - 1) * limit;
        map.put("data", materialMapper.selectMaterial(index, limit));
        return map;
    }
}
